/*
 * Created on 2004-11-28
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package cn.newtest.common.dbf;

/**
 * @author Administrator
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
import java.util.ArrayList;

public class DBFFile {
	public static JDBField[] copyField(String fileName) throws Exception {
		DBFReader dbfreader = new DBFReader(fileName);
		int fieldCount = dbfreader.getFieldCount();
		JDBField[] jdbfield = new JDBField[fieldCount];
		for (int i = 0; i < fieldCount; i++) {
			jdbfield[i] = dbfreader.getField(i);
			if (jdbfield[i].getType() == 'B') {
				jdbfield[i].setType('F');
			}
		}
		return jdbfield;
	}

	public static void writeFile(String fileName, String sourceFileName,
			ArrayList al) throws Exception {
		JDBField[] jdbFields = copyField(sourceFileName);
		DBFWriter dbfwriter = new DBFWriter(fileName, jdbFields, "UTF-8");
		Object[] obj = null;
		for (int i = 0; i < al.size(); i++) {
			obj = (Object[]) al.get(i);
			dbfwriter.addRecord(obj);
		}
		dbfwriter.close();
	}

	// public static void main(String[] args) {
	//		
	// }
}
